<?php
class UserAction extends Action {
    public function login(){
		layout(false); 
    	$this->display();
    }
    
public function checklogin(){
		
		$usernmae = $this->_post("username");
		$userpwd = $this->_post("password");
		
		if ($usernmae == '' || $userpwd == '')
			$this->error('请确认账号!');
			
		$condition['UserName'] = $usernmae;
		$condition['PassWord'] = $userpwd;
	
		$user = M('User')->where($condition)->select();
	
		if (!$user){
			$this->error("账号或密码错误!");
		}

		if ($user[0]['Status'] != 1){
			$this->error("您的账号被禁用，请与管理员联系!");
		}
		
		session('userid',$user[0]['Id']);
		session('username',$user[0]['UserName']);
		session('departid',$user[0]['DepartId']);

		
		$keeptime = 7*24*60*60*2;//保存2周

		if($this->_post("logged") == 'Value' ){
			cookie('keepLoged',true ,$keeptime);
			cookie('userid',$user[0]['Id'],$keeptime);  
			cookie('username',$user[0]['UserName'],$keeptime);
			cookie('departid',$user[0]['DepartId'],$keeptime);
		}
		
		//$this->success('操作成功','../Form/add');
		$this->redirect('/');
	}
}